<script type="text/javascript" charset="utf-8" src="__PUBLIC__/plugs/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/plugs/ueditor/ueditor.all.min.js"></script>
<link href="/Addons/Comment/Static/css/comment.css" rel="stylesheet" />
<script src="/Addons/Comment/Static/js/comment.js"></script>
<div class="container">
	{if condition="$config['position'] eq top"}
		{php}if(!session('user_auth')){{/php}
			<div class="dialog panel panel-default">
				<p class="">
					请先登录~~~~
				</p>
				<div class="panel-body">
					<p>
						<a href="{:U('User/Public/register')}">
							<button class="btn btn-warning" type="button">注册</button>
						</a>
						<a href="{:U('User/Public/login')}">
							<button class="btn btn-danger" type="button">登录</button>
						</a>
					</p>
				</div>
			</div>
		{php}}else{{/php}
				<form action="{:U('home/addons/execute',array('_addons'=>'Comment','_controller'=>'Comment','_action'=>'addComment'))}" class="addcomment form" method="post">
					<div class="Validform_checktip"></div>
					<div class="form-group">
						<input type="hidden" name="aid" value="{$info['id']}">
						<input type="hidden" name="model_id" value="{$info['model_id']}">
						{:W('Common/Form/show' , array('editor' , 'content'))}
					</div>
					<div class="form-group am-text-right">
						<button class="btn btn-primary ajax-post" target-form="addcomment" type="submit">发布评论</button>
					</div>
				</form>
			
		{php}}{/php}
	{/if}
	<div class="panel panel-default">
		<div class="panel-heading">评论啦~~</div>
		<div class="panel-body">
			{empty name="list"}
				暂时没有评论信息哦
			{/empty}
			{volist name="list" id="comment"}
				<article class="am-comment">
					<a href="#link-to-user-home">
						<img src="{:avatar($comment['uid'],'big')}">
					</a>
					<div class="am-comment-main">
						<header class="am-comment-hd">
						  <!--<h3 class="am-comment-title">评论标题</h3>-->
						  <div class="am-comment-meta">
						    <a href="#link-to-user" class="am-comment-author">{$comment['nickname']}</a>
						    评论于 <time datetime="{$comment['create_time']|time_format}" title="{$comment['create_time']|time_format}">{$comment['create_time']|time_format}</time>
						    评论数 {$comment['reply_num']}
						  </div>
						</header>

						<div class="am-comment-bd">
						  {$comment['content']}
						</div>
						{notempty name="comment[0]"}
						<div class="reply-footer"> 
							<div class="reply-box">
								<div class="showreply">
									<ul class="list-group">
										<div class="display-block">
										<li class="list-item">
											<div class="list-left am-fl">
												<img src="{:avatar($comment['uid'],'big')}">
											</div>
											<div class="list-right am-fl">
												<h2>{$comment[0]['nickname']}<small> 评论于 {$comment[0]['create_time']|time_format}</small></h2>
												<h3>{$comment[0]['content']}</h3>
											</div>
											<div class="am-cf"></div>
										</li>
										</div>
										<div class="display-none">

										</div>
									</ul>
								</div>
							</div>
						</div>
						{/notempty}
						<div class="reply-footer"> 
							<div class="reply-box">
								<a href="javascript:void(0);">
									<span class="ok-icon" data-id="{$comment['id']}">
										全部回复
									</span>
								</a>
							</div>
							<div class="reply-content">
								<div class="reply-box">
									<ul class="list-group">
										
									</ul>
								</div>
								<div class="reply-box">
									<a href="javascript:void(0);">
										<span class="cancel-icon" data-id="{$comment['id']}">
											收起回复
										</span>
									</a>
								</div>
								<form action="{:U('home/addons/execute',array('_addons'=>'Comment','_controller'=>'Comment','_action'=>'reply'))}" class="replycomment{$comment['id']}" method="post">
									<div class="am-form-group">
										<textarea class="content" name="content"></textarea>
									</div>
									<div class="form-group"> 
										<input type="hidden" name="commentid" value="{$comment['id']}" />
										<button class="btn btn-success reply-btn ajax-post" target-form="replycomment{$comment['id']}" type="submit">回复</button>
									</div>
								</form>
							</div>
						</div>
					</div>
				</article>
			{/volist}
		</div>
	</div>
	{if condition="$config['position'] eq 'bottom'"}
		{php}if(!session('user_auth')){{/php}
			<div class="dialog am-margin-bottom">
				<p>请先登录~~~~
					
				</p>
				<p>
					<a href="{:U('User/Public/register')}">
						<button class="am-btn am-btn-warning" type="button">注册</button>
					</a>
					<a href="{:U('User/Public/login')}">
						<button class="am-btn am-btn-danger" type="button">登录</button>
					</a>
				</p>
			</div>
		{php}}else{{/php}
				<form action="{:U('home/addons/execute',array('_addons'=>'Comment','_controller'=>'Comment','_action'=>'addComment'))}" class="addcomment" method="post">
					<div class="Validform_checktip"></div>
					<div class="am-form-group">
						<input type="hidden" name="aid" value="{$info['id']}">
						<input type="hidden" name="model_id" value="{$info['model_id']}">
						{:W('Common/Form/show' , array('editor' , 'content'))}
					</div>
					<div class="am-form-group am-text-right">
						<button class="am-btn am-btn-primary ajax-post" target-form="addcomment" type="submit">发布评论</button>
					</div>
				</form>
		{php}}{/php}
	{/if}
</div>
	<script>   
		$(function(){

			//展开回复按钮
			$('.ok-icon').click(function(){
				var showreply = $(this).parent().parent().parent().find('ul.list-group');
				showreply.html('');
				$.ajax({
					url : "{:U('home/addons/execute',array('_addons'=>'Comment','_controller'=>'Comment','_action'=>'getAllReply'))}",
					type : 'POST',
					data : {
						'commentid' : $(this).attr('data-id'),
					},
					success : function(response,status,xhr){
						var json = jQuery.parseJSON(response);
						$.each(json,function(index,value){
							showreply.append('<li class="list-item"><div class="list-left am-fl"><img src="{:avatar('+value.uid+','big')}"></div><div class="list-right am-fl"><h2>'+value.nickname+'<small> 评论于 '+value.create_time+'</small></h2><h3>'+value.content+'</h3></div><div class="am-cf"></div></li>');
						});
					}
				});
				$(this).hide();
				$(this).parent().parent().parent().find('div.reply-content').toggle();
				$(this).parent().parent().parent().find('div.reply-content')
			});

			//收起回复触发事件
			$('.cancel-icon').click(function(){
				$(this).parent().parent().parent().parent().find('div.reply-content').hide();
				$(this).parent().parent().parent().parent().parent().find('span.ok-icon').show();
			});

		});
	</script>